{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import xml.etree.cElementTree as et \n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "xml_tree = et.ElementTree(file='xxx.xml')  # 文件路径\n",
    "dfcols = ['sentence', 'opinionated', 'polarity']\n",
    "df_xml = pd.DataFrame(columns=dfcols)\n",
    "root = xml_tree.getroot();\n",
    "\n",
    "for sub_node in root:\n",
    "    for node in sub_node:\n",
    "        #print(node, node.tag, node.attrib, node.text)\n",
    "        sentence = node.text\n",
    "        opinionated = node.attrib.get('opinionated')\n",
    "        polarity = node.attrib.get('polarity')\n",
    "\n",
    "        df_xml = df_xml.append(\n",
    "            pd.Series([sentence, opinionated, polarity], index=dfcols),\n",
    "            ignore_index=True)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
